package com.coolingme.general;

import java.util.List;

/**
 * 具体迭代器
 *
 * @author wangyue
 * @date 2020-09-24 0:24
 */
public class ConcreteIterator<E> implements Iterator<E> {

    /**
     * 容器
     */
    private List<E> list;

    /**
     * 游标
     */
    private int cursor = 0;

    public ConcreteIterator(List<E> list) {
        this.list = list;
    }

    @Override
    public E next() {
        return this.list.get(cursor++);
    }

    @Override
    public boolean hasNext() {
//        return this.cursor < this.list.size();
        return this.cursor != this.list.size();
    }
}
